﻿/***************************************************/
/*** file:IHanleServer.cs                        ***/
/*** date:2010-08-15                             ***/
/*** author:huas                                 ***/
/*** function:implement database     interface   ***/
/***************************************************/



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IM.Common;
using System.Configuration;
using IM.Database;

namespace IM.Logic
{
    public class IMDatabase
    {
        private DataProvider dataProvider = null;
        private string connString = String.Empty;

        public IMDatabase()
        {
            string providerType = ConfigurationManager.AppSettings["DataProvider"].ToString();
            string oleDbConnString = ConfigurationManager.AppSettings["OleDbConnString"].ToString();
            string sqlServerConnString = ConfigurationManager.AppSettings["SqlServerConnString"].ToString();
            string mySqlConnString = ConfigurationManager.AppSettings["MySqlConnString"].ToString();
            DataProviderType type = (DataProviderType)Enum.Parse(typeof(DataProviderType), providerType, true);
            switch (type)
            {
                case DataProviderType.OleDbProvider :
                    connString = oleDbConnString;
                    break;
                case DataProviderType.SqlServerProvider :
                    connString = sqlServerConnString;
                    break;
                case DataProviderType.MySqlProvider :
                    connString = mySqlConnString;
                    break;
            }
            dataProvider = DataProvider.CreateInstance(type, connString);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="verify_result"></param>
        /// <param name="account_id"></param>
        /// <returns></returns>
        public bool GetAccountDetail(ref s2c_account_verify_result verify_result, int account_id)
        {
            return dataProvider.GetAccountDetail(ref verify_result, account_id);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strAccount"></param>
        /// <param name="strPwd"></param>
        /// <param name="account_id"></param>
        /// <returns></returns>
        public bool VerifyAccount(string strAccount, string strPwd, ref int account_id)
        {
            return dataProvider.VerifyAccount(strAccount, strPwd, ref account_id);
        }
    }
}
